/**
 * Created with Vim7.3 Mac
 * @fileOverview : 
 * @author : Lyle lylechen2014@gmail.com
 * @since : 2016-09-20 17:37:19
 * @filename : src/base/components/myProfileTpl.js
 * @version : 
 * @description : 
 */

define(function(require, exports, module) {

    var tpl = require('{base}/tpls/myProfileTpl.tpl'),
        pageBase = require('{base}/pages/pageBase.js'),
        head = require('{base}/components/head.js'),
        headStatus = require('{base}/components/headStatus.js'),
        myProfileInfo = require('{base}/components/myProfileInfo.js'),
        myProfileEditInfoNav = require('{base}/components/myProfileEditInfoNav.js'),
        foot = require('{base}/components/foot.js');

    var myProfile = _.extend(pageBase, {

        template: _.template(tpl),

        baseRender: function(obj) {
            Share.checkPermission(this.callBackRender.bind(this, obj));
        },

        callBackRender: function(obj) {
            $('body').html("<div id = '" + obj.name + "' class='page'>" +
                this.template({
                    head: head.render(this, obj),
                    headStatus: headStatus.render(this, obj),
                    myProfileInfo: myProfileInfo.render(this, obj),
                    myProfileEditInfoNav: myProfileEditInfoNav.render(this, obj),
                    foot: foot.render(this, obj)
                }) + "</div>");

            this.render(obj);

            this.bindEvtComponents($('#' + obj.name), [
                head,
                headStatus,
                myProfileInfo,
                myProfileEditInfoNav,
                foot
            ]);
        },

        bindEvtComponents: function(dom, arr) {
            for (var i in arr) {
                if (arr[i].componentMount) {
                    arr[i].componentMount();
                }
            }
        },

        baseUpdateComponents: function(type, data) {
            console.log('baseUpdateComponents', type, data);
            if (type == 'userInfo') {
                head.componentUpdate();
                myProfileInfo.componentUpdate();
            } else {

            }
        },

    })

    module.exports = myProfile;
});
